﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using ZK.HardWareBLL;

namespace ZK.YCGLRD_WindowsService
{
    public class YRTReaderController : ApiController
    {
        YRTRSNeaderBLL2 yRTRS;
        string epc;

        public YRTReaderController()
        {
            yRTRS = new YRTRSNeaderBLL2();
            yRTRS.getDataCallbackEvent = getDataCallback;
            epc = string.Empty;
        }

        private void getDataCallback(string epc)
        {
            this.epc = epc;
        }

        /// <summary>
        /// 获取卡号
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetCardNum()
        {
            yRTRS.OpenCom();
            yRTRS.BeginS();
            while (string.IsNullOrEmpty(this.epc))
            {
                System.Threading.Thread.Sleep(100);
            }

            yRTRS.Close();
            return this.epc;
        }

    }
}
